From f1fe144526a8288dd8cf8ab420aa8ec7df8767c2 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Sat, 3 Aug 2013 11:10:37 +0000 Subject: [PATCH] be more defensive with deallocation of dynamic memory in tpo. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4501 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/main.cc | 1 + gpsbabel/tpo.cc | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gpsbabel/main.cc b/gpsbabel/main.cc index eccf19259..cd75c613f 100644 --- a/gpsbabel/main.cc +++ b/gpsbabel/main.cc @@ -714,6 +714,7 @@ main(int argc, char* argv[]) ovecs->position_ops.wr_deinit(); } exit(0); +printf("early\n"); } diff --git a/gpsbabel/tpo.cc b/gpsbabel/tpo.cc index 1e5990826..ae05acb2d 100644 --- a/gpsbabel/tpo.cc +++ b/gpsbabel/tpo.cc @@ -1412,7 +1412,10 @@ static void tpo_rd_init(const char* fname) { + // preprare for an attempt to deallocate memory that may or may not get allocated + // depending on the options used. tpo_index_ptr = 0; + tpo_wp_index = NULL; tpo_file_in = gbfopen_le(fname, "rb", MYNAME); tpo_check_version_string(); @@ -1444,9 +1447,13 @@ tpo_rd_deinit(void) for (i = 0; i < tpo_index_ptr; i++) { waypt_free(tpo_wp_index[i]); } + tpo_index_ptr = 0; // Free the index array itself - xfree(tpo_wp_index); + if (tpo_wp_index) { + xfree(tpo_wp_index); + tpo_wp_index = NULL; + } gbfclose(tpo_file_in); } -- 2.30.2